import Vue from "vue";
import ElementUI from 'element-ui';
import 'element-ui/lib/theme-chalk/index.css';//样式单独引入
import App from "./App.vue";
import router from "./router";
import store from "./store";
import '@/styles/common.css' //全局css样式
import VueParticles from 'vue-particles'
Vue.use(VueParticles)
Vue.use(ElementUI);
Vue.config.productionTip = false;

import { isLogin } from '@/api'
//全局守卫 所有路由进入之前都会被拦截 如果不调用next 那么组件就不会被resolve
router.beforeEach((to, from, next) => {
  //如果用户去登入页面 就不要拦截 直接next()
  if (to.path === "/login" || to.path === "/regist") {
    next()
  } else {
    isLogin().then(res => {
      if (res.data.status !== 304) {//代表令牌未失效
        next()
      } else {
        next({ path: "/login" })//失效的话 跳转到登入页面
      }
    })
  }
})

new Vue({
  router,
  store,
  render: h => h(App)
}).$mount("#app");
